#ifndef UR_GOTO_H_
#define UR_GOTO_H_

// Default data boundaries
#define UR_GOTO_LATITUDE_MIN -180.0
#define UR_GOTO_LATITUDE_MAX 180.0
#define UR_GOTO_LONGITUDE_MIN -180.0
#define UR_GOTO_LONGITUDE_MAX 180.0
#define UR_GOTO_ALTITUDE_MIN -99.99f
#define UR_GOTO_ALTITUDE_MAX 9999.99f

#include "AbstractData.h"
/*
 * class URGoto
 * 
 * Represents position data for sentence to be sent from USTAV Router to USTAV Server.
 *
 *  Created on: 22.1.2012.
 *      Author: Hetcheem
 *
 * GOTO                 min         max  bytes  + comma    unit  data type
 * -----------------------------------------------------------------------
 * Latitude     -180.000000  180.000000     11       12     deg     double   (precision 1.11 cm)
 * Longitude    -180.000000  180.000000     11       12     deg     double
 * Altitude          -99.99     9999.99      7        8       m      float
 * -----------------------------------------------------------------------
 * TOTAL                                    29       32
 * BASE + GOTO                                       50
 */
class URGoto : public AbstractData
{
private:
    // Data members
    double m_latitude;
    double m_longitude;
    float m_altitude;

    // Data handling
    int SerializeSentence(std::stringstream& stream, const bool& isSending)
    {
        // Call base class serialization
        AbstractData::SerializeSentence(stream, isSending);

        if (isSending)
        {
            // Send data to stream
            stream << std::setprecision(6) << m_latitude << ',';
            stream << std::setprecision(6) << m_longitude << ',';
            stream << std::setprecision(2) << m_altitude;
        }
        else
        {
            char comma;
            double latitude, longitude;
            float altitude;
       
            // Recieve data from stream
            stream >> latitude >> comma;
            stream >> longitude >> comma;
            stream >> altitude;

            // Set the values
            SetLatitude(latitude);
            SetLongitude(longitude);
            SetAltitude(altitude);
        }

        return 0;
    }

public:

    // Constructor
    URGoto() : AbstractData("URGOT"),
    m_latitude(0), m_longitude(0), m_altitude(0)
    {}
    
    // Get
    inline const double& GetLatitude() { return m_latitude; }
    inline const double& GetLongitude() { return m_longitude; }
    inline const float& GetAltitude() { return m_altitude; }

    // Set
    int SetLatitude(const double& value)
    {
        if (value > UR_GOTO_LATITUDE_MAX)
        {
            m_latitude = UR_GOTO_LATITUDE_MAX;
            return 666;
        }
        else if (value < UR_GOTO_LATITUDE_MIN)
        {
            m_latitude = UR_GOTO_LATITUDE_MIN;
            return -666;
        }
 
        m_latitude = value;
        return 0;
    }

    int SetLongitude(const double& value)
    {
        if (value > UR_GOTO_LONGITUDE_MAX)
        {
            m_longitude = UR_GOTO_LONGITUDE_MAX;
            return 666;
        }
        else if (value < UR_GOTO_LONGITUDE_MIN)
        {
            m_longitude = UR_GOTO_LONGITUDE_MIN;
            return -666;
        }
 
        m_longitude = value;
        return 0;
    }

    int SetAltitude(const float& value)
    {
        if (value > UR_GOTO_ALTITUDE_MAX)
        {
            m_altitude = UR_GOTO_ALTITUDE_MAX;
            return 666;
        }
        else if (value < UR_GOTO_ALTITUDE_MIN)
        {
            m_altitude = UR_GOTO_ALTITUDE_MIN;
            return -666;
        }

        m_altitude = value;
        return 0;
    }
};

#endif /* UR_GOTO_H_ */